import java.util.HashMap;
import java.util.Map;

public class Main {
    public String minWindow(String ss, String tt) {
        char[] s = ss.toCharArray();
        char[] t = tt.toCharArray();

        int[] hash1 = new int[128];
        int kinds = 0; // 种类数量
        for (char ch : t) {
            if (hash1[ch] == 0){
                kinds++;
            }
            hash1[ch]++;
        }
        int[] hash2 = new int[128];

        int minlen = Integer.MAX_VALUE;
        int begin = -1;


        for (int left = 0, right = 0,count = 0; right < s.length;right++){
            char in = s[right];
            hash2[in]++;
            if (hash2[in] == hash1[in]){ //进窗口+维护count
                count++;
            }
            while (count == kinds){ //判断
                //更新结果
                if (right - left + 1 < minlen){
                    begin = left;
                    minlen = right - left + 1;
                }
                char out = s[left];
                left++;
                if (hash2[out] == hash1[out]){
                    count--;
                }
                hash2[out]--;
            }
        }
        if (begin == -1){
            return new String();
        }else {
            return ss.substring(begin,begin+minlen);
        }

    }
}
































